/**    
 * @Title: FileWriter.java  
 * @Package cn.com.ytst.data.integration.components.writer.file  
 * @Description: 
 * @author yanhewei@vv.cc.com    
 * @date 2020年7月6日 下午6:14:56  
 * @version V1.0    
*/
package cn.com.ytst.data.integration.components.writer.file;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;

import com.alibaba.datax.common.util.Configuration;

import cn.com.ytst.data.integration.core.plugin.Writer;
import lombok.extern.slf4j.Slf4j;

/**  
 * @ClassName: FileWriter  
 * @Description: 
 * @author yanhewei@vv.cc.com  
 * @date 2020年7月6日 下午6:14:56  
 *    
*/
@Slf4j
public class FileWriter extends Writer{

	
	private String path;
	
	private String filename;
	
	private String encode;
	
	private boolean append;
	
	@Override
	public void init() {
		Configuration writerConf = this.getPluginJobConf();
		this.filename = writerConf.getString(FileWriterKey.FILE_WRITER_FILENAME_TAG);
		this.path = writerConf.getString(FileWriterKey.FILE_WRITER_PATH_TAG);
		this.encode = writerConf.getString(FileWriterKey.FILE_WRITER_ENCODE_TAG);
		this.append = writerConf.getBool(FileWriterKey.FILE_WRITER_APPEND_TAG);
	}

	@Override
	public void startWriter(String line) {
		log.info("获取到数据:{}",line);
		try {
			FileUtils.write(new File(this.path + File.separator+this.filename), line, this.encode, append);
		} catch (IOException e) {
			log.error("",e);
		}
		
	}

	@Override
	public void destroy() {
		
	}

}
